LINUX_VERSION_CODE> = KERNEL_VERSION (2, 6, 0)# Define LINUX26# Endif# Ifdef LINUX26/* Code in 2.6 kernel */# Else/* Code in 2.4 kernel */# Endif
Back to Top2. kernel module Mechanism Changes2.1 Module CompilationFrom 2.4 to 2.6, the compilation, connection process, and Makefile Writing of external kernel modules have all changed.In the 2.4 kernel, only the kernel source code header file is required for MODULE compilation. The MODULE must be defined before linux/modules. h. The kernel MODULE ge
Mechanism Changes
2.1 Module Compilation
From 2.4 to 2.6, the compilation, connection process, and makefile Writing of external kernel modules have all changed.
In the 2.4 kernel, only the kernel source code header file is required for module compilation. The module must be defined before Linux/modules. h. The kernel module generated after compilation and connection is suffixed with. O.
2.6 kernel, the kernel source code to be configured for module compilation; the kernel module generated after
kernel, only the kernel source code header file is required for module compilation. The module must be defined before Linux/modules. h. The kernel module generated after compilation and connection is suffixed with. O.
2.6 kernel, the kernel source code to be configured for module compilation; the kernel module generated after compilation and connection is suffixed. ko; the compilation process first reads the MAKEFILE file at the top level under the kernel source code directory, and then returns
compilation and connection is suffixed. ko; the compilation process first reads the Makefile File at the top level under the kernel source code directory, and then returns the directory where the module source code is located.
Listing 2: 2. 4. Makefile template of the kernel module# Makefile2.4KVER = $ (shell uname-r)KDIR =/lib/modules/$ (KVER)/buildOBJS = mymodule. oCFLAGS =-d1_kernel _-I $ (KDIR)/include
kernel modules, the connection process, and the writing of makefile have changed.2.4 Kernel, the module compiles only the kernel source dock file, need to define module before including Linux/modules.h, the kernel module suffix that is generated after compiling and connecting is. O.2.6 Kernel, the module's compilation needs to be configured the kernel source code; The kernel module suffix generated after compiling and connecting is. Ko; the compilation process starts with the kernel source dire
: mini2440 (128 M nandflash) // for how to download linux to the Development Board, click. For Linux RootFs, select rootfs_rtm_2440.img (Disk Directory: image/linux/rtm)
Tools required for development: NFS network file minicom
Pc end:
First, create a self-written driver folder.
1. # mkdir/home/lianghuiyong/my2440drivers // create a folder
2. # cd/home/lianghuiyong/my2440drivers // enter the folder
3. # VIM helloworld. c
Helloworld. c content:
#include
In the code, module_init and module
I. module functions
1. Differences between kernel module programming and Linux application development:
(1) In kernel module programming, there is no main function (2) in kernel module programming, we use printk to print, without printf
2. program structure of the kernel module Program
(1) module Loading Function (required): The function automatically called by the system when the module is installed. It is specified by the module_init (XXX) Macro.
(2) module uninstallation function (required):
to describe the meaning of the parameter, without making a bunch of scripts. The following is an example of LDD3, in which CFLAGS is changed to EXTRA_CFLAGS. Another note is that a space must be added after ifeq; otherwise, an error is reported.
DEBUG = y
Ifeq ($ (DEBUG), y)
DEBFLAGS =-O-g-DSCULL_DEBUG
Else
DEBFLAGS =-O2
Endif
EXTRA_CFLAGS
+ =$ (DEBFLAGS)
OBJ-M: = scull. o
Module-objs: =
PWD: = $ (shell PWD)
Kdir: =/lib/modules/$ (shel
] #. /configure -- prefix =/usr/local/drbd -- with-km Note: -- with-km is used to enable the kernel module [root @ node1 ~] # Make KDIR =/usr/src/kernels/2.6.32-358. el6.i686 note KDIR path this kernel source code path needs to be modified according to their own system) [root @ node1 drbd-8.4.3] # make install [root @ node1 ~] # Mkdir-p/usr/local/drbd/var/run/drbd [root @ node1 ~] # Cp/usr/local/drbd/etc/rc
/0-code/0-thinkingl-code/trunk/thinkingl-codelib/Study/0-linuxdriver/0-helloworld/hello.mod.o LD [M] /disks/e/0-code/0-thinkingl-code/trunk/thinkingl-codelib/Study/0-linuxdriver/0-helloworld/hello.komake[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic'Then you can load and detach the module to test the effect:
insmod hello.kormmod hello.ko
The ssh command line may not be able to see the effect. See dmesg:
[133540.841098] Hello, world! I'm Lizhixing.[133553.819340] Good bye,
Makefile of the kernel module in Linux 2.6
Favorites
Makefile of the kernel module in Linux 2.6
# Makefile 2.6OBJ-M + = Hello. o
Kdir: =/lib/modules/$ (shell uname-R)/build# Pwd = $ (shell PWD)
ALL:Make-C $ (kdir) M = $ (PWD) ModulesClean:Make-C $ (kdir) M = $ (PWD) clean
OBJ-M: = Hello. O indicates that the hello. O module is generated after
;
Void set_symbol_addr (unsigned old_value, unsigned new_value)
{
Struct module * mod;
Struct kernel_symbol * s;
Int I;
For (mod = THIS_MODULE, s = mod-> syms, I = 0; I num_syms; ++ I, ++ s)
If (s-> value = old_value)
{
S-> value = new_value;
Return;
}
/* Traverses the symbol table of this module and calls an address of the symbol sys_call_table in this module.
Set it to the actual address of the system sys_call_table. */
}
Char * findoffset (char * start)
{
Char * p;
For (p = start; p off
desired? Too many FILES $ _ FILES [{€?* UploadFile? Why? Why? | Too many threads? Why? . Jpg |. bmp |. gif)/*-= -= */Function uploadFile ($ ufile, $ updir, $ upfile, $ upexf = "") {// note here $ upexf = "" if the author thinks it is necessary to design a variable of .jpg |. bmp |. gif "! After investigation, global variables are set at the end. Finally, pass the value in!$ Base_dir = $ updir; // obtain the upload path$ Kdir = str_replace ($ _ SERVER
, perm ). Type is a type, such as bool, invbool, charp, int, long, short, uint, ulong, and ushort. Num is actually the length of array. Perm is permission, and the related values can be found in linux/stat. h. S_IRUGO indicates read-only, and can be read or written as S_IRGO | S_IWUSR. 0 indicates no sysfs. When calling, we can use insmod hello. ko whom = "Mom" howloud = 5 is used to provide the parameter. We can choose not to give the parameter, use the default value, or just give one of the pa
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.